<template>
  <div class="container">
    <div class="each">
      <div class="num">{{OrderEchartsValue[0]}}</div>
      <div class="status">{{textArr[0]}}</div>
    </div>
    <div class="each">
      <div class="num">{{down}}</div>
      <div class="status">{{textArr[1]}}</div>
    </div>
    <div class="each">
      <div class="num">{{classify}}</div>
      <div class="status">{{textArr[2]}}</div>
    </div>
    <div class="each">
      <div class="num">{{count}}</div>
      <div class="status">{{textArr[3]}}</div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import service from '@/utils/http'

export default {
  props: {
    textArr: [],
    url: {
      type: String,
      default: null
    }
  },
  data () {
    return {
      up: 0,
      down: 0,
      classify: 0,
      count: 0,
      SaleEchartsDays: [],
      OrderEchartsValue: [0, 0, 0, 0, 0, 0, 0]
    }
  },
  methods: {
    async getDay () {
      const days = []
      // eslint-disable-next-line no-tabs
      for (let i = 0; i <= 24 * 6; i += 24) {		// 今天加上前6天
        const dateItem1 = new Date()
        const dateItem = new Date(dateItem1.getTime() - i * 60 * 60 * 1000)// 使用当天时间戳减去以前的时间毫秒（小时*分*秒*毫秒）
        const y = dateItem.getFullYear()// 获取年份
        let m = dateItem.getMonth() + 1// 获取月份js月份从0开始，需要+1
        let d = dateItem.getDate()// 获取日期
        m = this.addDate0(m)// 给为单数的月份补零
        d = this.addDate0(d)// 给为单数的日期补零
        const valueItem = y + '-' + m + '-' + d// 组合
        days.push(valueItem)// 添加至数组
      }
      console.log('最近七天日期：', days)
      this.SaleEchartsDays = days
      return days
    },

    addDate0 (time) {
      if (time.toString().length === 1) {
        time = '0' + time.toString()
      }
      return time
    }
  },
  mounted () {
    this.getDay()
    axios.get(this.url).then(res => {
      // console.log(res)
      this.up = res.data.result.up
      // this.down = res.data.result.down
      // this.classify = res.data.result.classify
      // this.total = res.data.result.total
    })
    // service.get('menu/count', {
    // })
    //   .catch(error => {
    //     console.log(error)
    //   })
    //   .then(res => {
    //     console.log(res)
    //     this.total = res.data.data
    //     console.log(this.total)
    //   })
    service.get('consumer/count', {
    })
      .catch(error => {
        console.log(error)
      })
      .then(res => {
        console.log(res)
        this.count = res.data.data
        console.log(this.total)
      })
    service.post('getDayMpNumByDate', {
      data: this.SaleEchartsDays[0]
    })
      .catch(error => {
        console.log(error)
      })
      .then(res => {
        console.log(res.data)
        this.OrderEchartsValue[0] = res.data
      })
  }
}
</script>

<style scoped lang='less'>
.container {
  display: flex;
  justify-content: space-around;
  margin-bottom: 10px;
  .each {
    color: #666;
    text-align: left;
    .num {
      display: flex;
      justify-content: center;
      font-size: 48px;
    }
    .status {
      display: flex;
      justify-content: center;
      font-size: 18px;
    }
  }
}
</style>
